Phalcon Framework 4.1.2

MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling hello on 'localhost:27017']

/home/ebooking/sites/models/MainDB.php (96)
#0MongoDB\Driver\Manager->executeQuery(butashop.categories, Object(MongoDB\Driver\Query))
/home/ebooking/sites/models/MainDB.php (96)
  1. <?php
  2. namespace Multiple\Models;
  3.  
  4. class MainDB
  5. {
  6. public static $connection = false;
  7.  
  8. public static $db = "butashop";
  9.  
  10. public static $collection = false;
  11.  
  12. public static function getSource()
  13. {
  14. return null;
  15. }
  16.  
  17. public static function setCollection($collection)
  18. {
  19. self::$collection = $collection;
  20. }
  21.  
  22. public static function init()
  23. {
  24. self::$collection = static::getSource();
  25. if(!self::$connection)
  26. self::$connection = new \MongoDB\Driver\Manager('mongodb://localhost:27017/'.self::$db);
  27. }
  28.  
  29. public static function insert($data)
  30. {
  31. self::init();
  32. $insRec = new \MongoDB\Driver\BulkWrite;
  33. $id = $insRec->insert($data);
  34. $result = self::$connection->executeBulkWrite(self::$db.'.'.self::$collection, $insRec);
  35.  
  36. if($result)
  37. {
  38. return $id;
  39. }
  40. else
  41. {
  42. return false;
  43. }
  44. }
  45.  
  46. /**
  47. public static function save($data)
  48. {
  49. return self::insert($data);
  50. } */
  51.  
  52.  
  53. public function save()
  54. {
  55. $ins = [];
  56. foreach($this as $key => $value)
  57. {
  58. if($key !== "_id")
  59. $ins[$key] = $value;
  60. }
  61.  
  62. if($this->_id)
  63. {
  64. self::update(["_id" => $this->_id], $ins);
  65. //exit(json_encode($this));
  66. return (string)$this->_id;
  67. }
  68. return self::insert($ins);
  69. }
  70.  
  71.  
  72. public static function count($array = [])
  73. {
  74. $filter = (@$array[0]) ? $array[0]: [];
  75. $options = [];
  76. self::init();
  77.  
  78. $Command = new \MongoDB\Driver\Command(["count" => self::$collection, "query" => $filter]);
  79. $Result = self::$connection->executeCommand(self::$db, $Command);
  80. return $Result->toArray()[0]->n;
  81. }
  82.  
  83. public static function find($array = [])
  84. {
  85. $filter = (@$array[0]) ? $array[0]: [];
  86. $options = [];
  87. if(isset($array["limit"]))
  88. $options["limit"] = @$array["limit"];
  89. if(isset($array["sort"]))
  90. $options["sort"] = @$array["sort"];
  91. if(isset($array["skip"]))
  92. $options["skip"] = $array["skip"];
  93. self::init();
  94.  
  95. $query = new \MongoDB\Driver\Query($filter, $options);
  96. $rows = self::$connection->executeQuery(self::$db.'.'.self::$collection, $query);
  97.  
  98. return $rows->toArray();
  99. }
  100.  
  101. public static function findById($id)
  102. {
  103. if(strlen($id) < 5)
  104. return false;
  105. $filter["_id"] = self::objectId($id);
  106. self::init();
  107. $query = new \MongoDB\Driver\Query($filter, []);
  108. $rows = self::$connection->executeQuery(self::$db.'.'.self::$collection, $query);
  109. foreach($rows as $row)
  110. {
  111. $obj = new static();
  112. foreach($row as $k => $v){
  113. $obj->{$k} = $v;
  114. }
  115. return $obj;
  116. }
  117. return false;
  118. }
  119.  
  120. public static function findFirst($array = [])
  121. {
  122. $filter = (@$array[0]) ? $array[0]: [];
  123. $options = [];
  124. $options["limit"] = 1;
  125. if(isset($array["sort"]))
  126. $options["sort"] = @$array["sort"];
  127. if(isset($array["skip"]))
  128. $options["skip"] = $array["skip"];
  129. self::init();
  130. $query = new \MongoDB\Driver\Query($filter, $options);
  131. $rows = self::$connection->executeQuery(self::$db.'.'.self::$collection, $query);
  132. foreach($rows as $row)
  133. {
  134. $obj = new static();
  135. foreach($row as $k => $v){
  136. $obj->{$k} = $v;
  137. }
  138. return $obj;
  139. }
  140. return false;
  141. }
  142.  
  143. public static function sum($field, $filter=[])
  144. {
  145. self::init();
  146.  
  147. $pipleLine = [];
  148. if(count($filter) > 0)
  149. $pipleLine[] = ['$match' => $filter];
  150.  
  151. $pipleLine[] = [
  152. '$group' => ['_id' => '$asdaksdkaskk', 'total' => ['$sum' => '$'.$field], 'count' => ['$sum' => 1]],
  153. ];
  154.  
  155. $Command = new \MongoDB\Driver\Command([
  156. 'aggregate' => self::$collection,
  157. 'pipeline' => $pipleLine,
  158. //'cursor' => new stdClass,
  159. ]);
  160.  
  161. $Result = self::$connection->executeCommand(self::$db, $Command);
  162.  
  163. //echo var_dump($field);
  164. //echo "<pre>";var_dump($Result->toArray()[0]->result[0]);exit;
  165. return $Result->toArray()[0]->result[0]->total;
  166. }
  167.  
  168. public static function update($filter, $data)
  169. {
  170. self::init();
  171. $options = ['multi' => true, 'upsert' => false];
  172. $insRec = new \MongoDB\Driver\BulkWrite;
  173. $insRec->update(
  174. $filter,
  175. ['$set' => $data],
  176. $options
  177. );
  178. $result = self::$connection->executeBulkWrite(self::$db.'.'.self::$collection, $insRec);
  179.  
  180. if($result)
  181. {
  182. return true;
  183. }
  184. else
  185. {
  186. return false;
  187. }
  188. }
  189.  
  190. public static function increment($filter, $data)
  191. {
  192. self::init();
  193. $options = ['multi' => true, 'upsert' => false];
  194. $insRec = new \MongoDB\Driver\BulkWrite;
  195. $insRec->update(
  196. $filter,
  197. ['$inc' => $data],
  198. $options
  199. );
  200. $result = self::$connection->executeBulkWrite(self::$db.'.'.self::$collection, $insRec);
  201.  
  202. if($result)
  203. {
  204. return true;
  205. }
  206. else
  207. {
  208. return false;
  209. }
  210. }
  211.  
  212. public static function updateAndIncrement($filter, $update, $increment)
  213. {
  214. self::init();
  215. $options = ['multi' => true, 'upsert' => false];
  216. $insRec = new \MongoDB\Driver\BulkWrite;
  217. $insRec->update(
  218. $filter,
  219. [
  220. '$set' => $update,
  221. '$inc' => $increment
  222. ],
  223. $options
  224. );
  225. $result = self::$connection->executeBulkWrite(self::$db.'.'.self::$collection, $insRec);
  226.  
  227. if($result)
  228. {
  229. return true;
  230. }
  231. else
  232. {
  233. return false;
  234. }
  235. }
  236.  
  237. public static function delete($filter)
  238. {
  239. self::init();
  240. $bulk = new \MongoDB\Driver\BulkWrite;
  241. $bulk->delete($filter, ['limit' => 0]);
  242. $result = self::$connection->executeBulkWrite(self::$db.'.'.self::$collection, $bulk);
  243. if($result)
  244. {
  245. return true;
  246. }
  247. else
  248. {
  249. return false;
  250. }
  251. }
  252.  
  253. public static function getDate($time=false, $currentTimezone=false)
  254. {
  255. if(!$time)
  256. $time=time();
  257. $time *= 1000;
  258. $datetime = new \MongoDB\BSON\UTCDateTime($time);
  259. return $datetime;
  260. }
  261.  
  262. public function dateTime($date, $currentTimezone=false)
  263. {
  264. $addTime = ($currentTimezone) ? 0: TIME_DIFF;
  265. $unixtime = 0;
  266. if($date && method_exists($date, "toDateTime"))
  267. $unixtime = strtotime(@$date->toDateTime()->format("Y-m-d H:i:s")) + $addTime;
  268. return $unixtime;
  269. }
  270.  
  271. public function dateFormat($date, $format = "Y-m-d H:i:s", $currentTimezone=false)
  272. {
  273. $addTime = ($currentTimezone) ? 0: TIME_DIFF;
  274. if($date && method_exists($date, "toDateTime"))
  275. $unixtime = strtotime(@$date->toDateTime()->format("Y-m-d H:i:s")) + $addTime;
  276. if(@$unixtime)
  277. return date($format, $unixtime);
  278. return 0;
  279. }
  280.  
  281. public function toSeconds($date, $currentTimezone=false)
  282. {
  283. $addTime = ($currentTimezone) ? 0: TIME_DIFF;
  284. if($date && method_exists($date, "toDateTime"))
  285. return round(@$date->toDateTime()->format("U.u"), 0) + $addTime;
  286. return 0;
  287. }
  288.  
  289. public static function objectId($id)
  290. {
  291. if(strlen($id) < 5)
  292. return false;
  293. return new \MongoDB\BSON\ObjectID($id);
  294. }
  295.  
  296.  
  297. public function getUnixtime()
  298. {
  299. return time() + 0;
  300. }
  301.  
  302. }
#1Multiple\Models\MainDB::find(Array([0] => Array(), [sort] => Array([index_id] => 1)))
/home/ebooking/sites/erobooking.com/apps/library/Acl.php (141)
  1. <?php
  2. use \Phalcon\Events\Event;
  3. use \Phalcon\Mvc\Dispatcher;
  4. use \Phalcon\Http\Response\Cookies;
  5.  
  6. use Multiple\Models\Users;
  7. use Multiple\Models\MongoKeywords;
  8. use Multiple\Models\MongoHitlogs;
  9. use Multiple\Models\MongoCategories;
  10. use Multiple\Models\Languages;
  11. use Multiple\Models\MongoColors;
  12. use Multiple\Models\MongoMaterial;
  13. use Multiple\Models\MongoProductCountry;
  14. use Multiple\Models\MongoProductOptions;
  15. use Multiple\Models\MongoForWhat;
  16. use Multiple\Models\MongoBrands;
  17. use Multiple\Models\Currency;
  18. use Multiple\Models\MongoCountry;
  19. use Multiple\Models\Cache;
  20. use Multiple\Models\MainDB;
  21.  
  22. use Lib\Lib;
  23.  
  24. class Acl extends \Phalcon\Di\Injectable
  25. {
  26. protected $_module;
  27.  
  28. protected $error;
  29.  
  30. public function __construct($module)
  31. {
  32. $this->_module = $module;
  33. }
  34.  
  35. public function auth()
  36. {
  37. if(!@$_COOKIE["ref"]){
  38. setcookie("ref", $this->request->getHTTPReferer(), time()+300*24*3600, "/");
  39. }
  40. $data = false;
  41. if ($this->request->get("logout")){
  42. Users::destroyCookie();
  43. }else if($_COOKIE['u_id']){
  44. $data = Users::getById($_COOKIE['u_id']);
  45. if (!$data){
  46. Users::destroyCookie();
  47. }elseif(Lib::generatePassword($data->password) == $_COOKIE['u_pw'] && (int)@$data->active == 1){
  48. Users::$id = $data->id;
  49. Users::$data = $data;
  50. Users::$data->visited_at = date("Y-m-d H:i:s");
  51. Users::$data->save();
  52. }else{
  53. Users::destroyCookie();
  54. }
  55. }
  56. $this->view->setVar("user_data", $data);
  57. }
  58.  
  59. public function initLang()
  60. {
  61.  
  62. }
  63.  
  64. public function botLog(){
  65. if (strpos(strtolower($this->request->getServer("HTTP_USER_AGENT")), "bot") == false && !$this->request->isAjax()){
  66. $H = new MongoHitlogs();
  67. $H->url = urldecode($this->request->getServer("REQUEST_URI"));
  68. $H->user_id = (float)@Users::$id;
  69. $H->ip = $this->request->getServer("REMOTE_ADDR");
  70. $H->useragent = $this->request->getServer("HTTP_USER_AGENT");
  71. $H->referer = $this->request->getServer("HTTP_REFERER");
  72. $H->bot = strpos(strtolower($this->request->getServer("HTTP_USER_AGENT")), "googlebot") > 0 ? "google": "other";
  73. $H->domain = _SITEURL_;
  74. $H->domain_id = DOMAIN_ID;
  75. $H->date = MainDB::getDate();
  76. //$H->save();
  77. }
  78. }
  79.  
  80. public function initCurrency()
  81. {
  82. switch(_LANG_){
  83. default:$currency = 4;break;
  84. case 'az':$currency = 5;break;
  85. case 'ru':$currency = 2;break;
  86. case 'en':$currency = 1;break;
  87. case 'ua':$currency = 4;break;
  88. }
  89. if(@Currency::$currencies[$this->request->get("currency")]){
  90. $currency = $this->request->get("currency");
  91. setcookie("currency", $currency, time()+365*24*3600, "/");
  92. }elseif(@Currency::$currencies[@$_COOKIE["currency"]]){
  93. $currency = $_COOKIE["currency"];
  94. }
  95. define("_CURRENCY_", $currency);
  96. }
  97.  
  98. public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
  99. {
  100. self::initCurrency();
  101. self::auth();
  102. self::botLog();
  103. define("_ROOT_", "/"._LANG_);
  104. define("_PAYMENT_CURRENCY_", 4);
  105. define("_PRICE_PERCENT_", 1);
  106. define("MIN_PAYMENT_AMOUNT", 1000);
  107. define("PRODUCT_DEFAULT_LANG", "ru");
  108.  
  109.  
  110. $scheme = json_decode($this->request->getServer("HTTP_CF_VISITOR"), true);
  111. if($scheme["scheme"] !== "https"){
  112. if(DOMAIN_ID == 5)
  113. {
  114. $redirect = "https://butashop.biz" . $_SERVER['REQUEST_URI'];
  115. }
  116. else
  117. {
  118. $redirect= "https://butashop.com".$_SERVER['REQUEST_URI'];
  119. }
  120. header("HTTP/1.1 301 Moved Permanently");
  121. header("Location:$redirect");
  122. exit;
  123. }
  124.  
  125.  
  126. if($dispatcher->getControllerName() !== "auth" && !Users::$data){
  127. //header("Location: /auth/login");
  128. //exit;
  129. }
  130.  
  131. $cat_arr = Cache::get("s_cat_arr_"._LANG_."_".DOMAIN_ID);
  132. $cat_data = Cache::get("s_cat_data_"._LANG_."_".DOMAIN_ID);
  133. $cat_ids = Cache::get("s_cat_ids_"._LANG_."_".DOMAIN_ID);
  134. if(!$cat_arr || !$cat_data){
  135. if((int)DOMAIN_ID == 5){
  136. $binds = ["visible" => 1];
  137. }else{
  138. $binds = [];
  139. }
  140. $cat_query = MongoCategories::find([
  141. $binds,
  142. "sort" => ["index_id" => 1]
  143. ]);
  144. $cat_arr = [];
  145. $cat_data = [];
  146. $cat_ids = [];
  147. $lang_keys = [];
  148.  
  149. IF (count($cat_query) > 0){
  150. foreach($cat_query as $value){
  151. $cat_ids[] = (int)$value->id;
  152. $lang_keys[] = $value->lang_key;
  153. $cat_arr[(int)$value->parent_id][] = (int)$value->id;
  154. $cat_data[(int)$value->id] = [
  155. "id" => (int)$value->id,
  156. "parent_id" => (int)$value->parent_id,
  157. "title" => (@$value->title->{_LANG_}) ? $value->title->{_LANG_}: $value->title->{$value->default_lang},
  158. ];
  159. }
  160.  
  161. Cache::set("s_cat_arr_"._LANG_."_".DOMAIN_ID, $cat_arr, 3600);
  162. Cache::set("s_cat_data_"._LANG_."_".DOMAIN_ID, $cat_data, 3600);
  163. Cache::set("s_cat_ids_"._LANG_."_".DOMAIN_ID, $cat_ids, 3600);
  164. }
  165. }
  166. MongoCategories::$cat_arr = $cat_arr;
  167. MongoCategories::$cat_data = $cat_data;
  168. MongoCategories::$cat_ids = $cat_ids;
  169.  
  170. Users::$is_bot = $is_bot = (strpos($this->request->getServer("HTTP_USER_AGENT"), "bot") == false) ? false: true;
  171.  
  172. $keywords = [];
  173. if($is_bot){
  174. if($_SERVER["REMOTE_ADDR"] == "212.90.33.98"){
  175. //exit("ok");
  176. }
  177. if(DOMAIN_ID == 3 && _LANG_ !== 3){
  178. //header("Location: /ru/".substr($this->request->getServer("REQUEST_URI"),4));
  179. //exit;
  180. }
  181. $keyword_count = Cache::get("buta_keyword_count_"._LANG_);
  182. if(!$keyword_count){
  183. $keyword_count = MongoKeywords::count([
  184. ["lang" => _LANG_]
  185. ]);
  186. Cache::set("buta_keyword_count_"._LANG_, $keyword_count, 2*3600);
  187. }
  188.  
  189. if($keyword_count > 0){
  190. $keyword_query = MongoKeywords::find([
  191. ["lang" => _LANG_],
  192. "limit" => 50,
  193. "skip" => abs(rand(0,$keyword_count) - 50),
  194. "sort" => [
  195. "index_id" => 1
  196. ]
  197. ]);
  198. $keyword = "";
  199. foreach($keyword_query as $value){
  200. //if(rand(1,10) == 1 && strlen($keyword.$value->keyword) < 90){
  201. // $keyword .= " ".$value->keyword;
  202. //}else{
  203. $keyword = $value->keyword;
  204. //}
  205. $keywords[] = [
  206. "name" => trim($keyword),
  207. "lang" => $value->lang[0],
  208. ];
  209. }
  210. }
  211.  
  212. }
  213.  
  214. $keyword_domains = [
  215. "az" => "az.butashop.com",
  216. "ua" => "butashop.com.ua",
  217. "ru" => "butashop.ru",
  218. "en" => "butashop.com",
  219. ];
  220. if(DOMAIN_ID == 2)
  221. $keyword_domains["ru"] = "butashop.com.ua";
  222. if(DOMAIN_ID == 1 && rand(1,3) == 1){
  223. $keyword_domains = [];
  224. }
  225.  
  226. if((int)DOMAIN_ID == 5){
  227. Languages::$langs = ["ua", "en", "ru"];
  228. }
  229.  
  230. $this->view->setVar("is_bot", $is_bot);
  231. $this->view->setVar("cat_arr", $cat_arr);
  232. $this->view->setVar("cat_data", $cat_data);
  233. $this->view->setVar("keywords", $keywords);
  234. $this->view->setVar("keyword_domains", $keyword_domains);
  235. $this->view->setVar("Lang", Languages::$lang_data);
  236. $this->view->setVar("Language", new Languages());
  237. $this->view->setVar("Lib", new Lib());
  238. $this->view->setVar("currencies", Currency::getByList());
  239. $this->view->setVar("colors", MongoColors::getByList());
  240. $this->view->setVar("materials", MongoMaterial::getByList());
  241. $this->view->setVar("product_country", MongoProductCountry::getByList());
  242. $this->view->setVar("product_options", MongoProductOptions::getByList());
  243. $this->view->setVar("countries", MongoCountry::getByList());
  244. $this->view->setVar("for_whats", MongoForWhat::getByList());
  245. $this->view->setVar("brands", MongoBrands::getByList());
  246. $this->view->setVar("genders", [1 => "Male", 2 => "Female", 3 => "Unisex"]);
  247.  
  248. $this->view->setVar("controller", $dispatcher->getControllerName());
  249. $this->view->setVar("action", $dispatcher->getActionName());
  250. $this->view->setVar("error", $this->error);
  251. }
  252.  
  253. }
#2Acl->beforeExecuteRoute(Object(Phalcon\Events\Event), Object(Phalcon\Mvc\Dispatcher), null)
#3Phalcon\Events\Manager->fireQueue(Object(SplPriorityQueue), Object(Phalcon\Events\Event))
#4Phalcon\Events\Manager->fire(dispatch:beforeExecuteRoute, Object(Phalcon\Mvc\Dispatcher))
#5Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#6Phalcon\Mvc\Application->handle(/az/view/2736/%3C)
/home/ebooking/sites/erobooking.com/public/index.php (152)
  1. <?php
  2. error_reporting(1);
  3. mb_internal_encoding('utf-8');
  4. ini_set("display_errors", "1");
  5.  
  6. define("EMAIL_DOMAIN", "http://sualcavab.az/msend.php");
  7.  
  8. class Application extends \Phalcon\Mvc\Application
  9. {
  10. /**
  11. * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  12. */
  13. protected function _registerServices()
  14. {
  15. $di = new \Phalcon\DI\FactoryDefault();
  16.  
  17. $loader = new \Phalcon\Loader();
  18.  
  19. /**
  20. * We're a registering a set of directories taken from the configuration file
  21. */
  22. $loader->registerDirs(
  23. array(
  24. __DIR__ . '/../apps/library/'
  25. )
  26. )->register();
  27.  
  28. define('DEBUG', true);
  29. if(DEBUG) {
  30. error_reporting(1);
  31. (new Phalcon\Debug)->listen();
  32. }
  33.  
  34. // DB connection
  35. $di->set('db', function () {
  36. return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
  37. "host" => "localhost",
  38. "username" => "ebooking",
  39. "password" => "ebooking",
  40. "dbname" => "ebooking",
  41. "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')
  42. ));
  43. });
  44.  
  45.  
  46.  
  47. //Registering a router
  48. $di->set('router', function(){
  49.  
  50. $router = new \Phalcon\Mvc\Router();
  51.  
  52. $router->setDefaultModule("frontend");
  53. $router->setDefaultController("index");
  54. $router->setDefaultAction("index");
  55. $router->removeExtraSlashes(true);
  56.  
  57. $router->add('/:controller/:action/:int', array(
  58. 'controller' => 1,
  59. 'action' => 2,
  60. 'id' => 3,
  61. ));
  62.  
  63. $router->add('/:controller/:action', array(
  64. 'controller' => 1,
  65. 'action' => 2,
  66. ));
  67.  
  68. $router->add('/:controller', array(
  69. 'controller' => 1,
  70. ));
  71.  
  72. $router->add('/{language:[a-z]{2}}/:controller/:action/:int/:int', array(
  73. 'controller' => 2,
  74. 'action' => 3,
  75. 'lang' => 1,
  76. 'id' => 4,
  77. 'page' => 5,
  78. ));
  79.  
  80.  
  81. $router->add("/{language:[a-z]{2}}/:params", array(
  82. 'controller' => 'index',
  83. 'action' => 'index',
  84. 'lang' => 1,
  85. 'keyword' => 2,
  86. ));
  87.  
  88. $router->add('/{language:[a-z]{2}}/:controller/:action/:int', array(
  89. 'controller' => 2,
  90. 'action' => 3,
  91. 'id' => 4,
  92. 'lang' => 1,
  93. ));
  94.  
  95. $router->add('/{language:[a-z]{2}}/:controller/:action', array(
  96. 'controller' => 2,
  97. 'action' => 3,
  98. 'lang' => 1,
  99. ));
  100.  
  101. $router->add("/{language:[a-z]{2}}/:controller", array(
  102. 'controller' => 2,
  103. 'lang' => 1,
  104. ));
  105.  
  106. $router->add("/{language:[a-z]{2}}/view/:int", array(
  107. 'controller' => 'products',
  108. 'action' => 'view',
  109. 'id' => 2,
  110. 'lang' => 1,
  111. ));
  112.  
  113. $router->add("/{language:[a-z]{2}}/view/:int/:params", array(
  114. 'controller' => 'products',
  115. 'action' => 'view',
  116. 'id' => 2,
  117. 'lang' => 1,
  118. ));
  119.  
  120. $router->add('/{language:[a-z]{2}}/news/:int/:params', array(
  121. 'controller' => "news",
  122. 'action' => "view",
  123. 'lang' => 1,
  124. 'id' => 2,
  125. 'slug' => 3,
  126. ));
  127.  
  128. $router->add("/{language:[a-z]{2}}", array(
  129. 'lang' => 1,
  130. ));
  131.  
  132. return $router;
  133.  
  134. });
  135.  
  136. $this->setDI($di);
  137. }
  138.  
  139. public function main()
  140. {
  141. $this->_registerServices();
  142.  
  143. //Register the installed modules
  144. $this->registerModules(array(
  145. 'frontend' => array(
  146. 'className' => 'Multiple\Frontend\Module',
  147. 'path' => '../apps/frontend/Module.php'
  148. )
  149. ));
  150.  
  151. $request = new Phalcon\Http\Request();
  152. echo $this->handle($request->getURI())->getContent();
  153. }
  154.  
  155. }
  156.  
  157. $application = new Application();
  158. $application->main();
#7Application->main()
/home/ebooking/sites/erobooking.com/public/index.php (158)
  1. <?php
  2. error_reporting(1);
  3. mb_internal_encoding('utf-8');
  4. ini_set("display_errors", "1");
  5.  
  6. define("EMAIL_DOMAIN", "http://sualcavab.az/msend.php");
  7.  
  8. class Application extends \Phalcon\Mvc\Application
  9. {
  10. /**
  11. * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  12. */
  13. protected function _registerServices()
  14. {
  15. $di = new \Phalcon\DI\FactoryDefault();
  16.  
  17. $loader = new \Phalcon\Loader();
  18.  
  19. /**
  20. * We're a registering a set of directories taken from the configuration file
  21. */
  22. $loader->registerDirs(
  23. array(
  24. __DIR__ . '/../apps/library/'
  25. )
  26. )->register();
  27.  
  28. define('DEBUG', true);
  29. if(DEBUG) {
  30. error_reporting(1);
  31. (new Phalcon\Debug)->listen();
  32. }
  33.  
  34. // DB connection
  35. $di->set('db', function () {
  36. return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
  37. "host" => "localhost",
  38. "username" => "ebooking",
  39. "password" => "ebooking",
  40. "dbname" => "ebooking",
  41. "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')
  42. ));
  43. });
  44.  
  45.  
  46.  
  47. //Registering a router
  48. $di->set('router', function(){
  49.  
  50. $router = new \Phalcon\Mvc\Router();
  51.  
  52. $router->setDefaultModule("frontend");
  53. $router->setDefaultController("index");
  54. $router->setDefaultAction("index");
  55. $router->removeExtraSlashes(true);
  56.  
  57. $router->add('/:controller/:action/:int', array(
  58. 'controller' => 1,
  59. 'action' => 2,
  60. 'id' => 3,
  61. ));
  62.  
  63. $router->add('/:controller/:action', array(
  64. 'controller' => 1,
  65. 'action' => 2,
  66. ));
  67.  
  68. $router->add('/:controller', array(
  69. 'controller' => 1,
  70. ));
  71.  
  72. $router->add('/{language:[a-z]{2}}/:controller/:action/:int/:int', array(
  73. 'controller' => 2,
  74. 'action' => 3,
  75. 'lang' => 1,
  76. 'id' => 4,
  77. 'page' => 5,
  78. ));
  79.  
  80.  
  81. $router->add("/{language:[a-z]{2}}/:params", array(
  82. 'controller' => 'index',
  83. 'action' => 'index',
  84. 'lang' => 1,
  85. 'keyword' => 2,
  86. ));
  87.  
  88. $router->add('/{language:[a-z]{2}}/:controller/:action/:int', array(
  89. 'controller' => 2,
  90. 'action' => 3,
  91. 'id' => 4,
  92. 'lang' => 1,
  93. ));
  94.  
  95. $router->add('/{language:[a-z]{2}}/:controller/:action', array(
  96. 'controller' => 2,
  97. 'action' => 3,
  98. 'lang' => 1,
  99. ));
  100.  
  101. $router->add("/{language:[a-z]{2}}/:controller", array(
  102. 'controller' => 2,
  103. 'lang' => 1,
  104. ));
  105.  
  106. $router->add("/{language:[a-z]{2}}/view/:int", array(
  107. 'controller' => 'products',
  108. 'action' => 'view',
  109. 'id' => 2,
  110. 'lang' => 1,
  111. ));
  112.  
  113. $router->add("/{language:[a-z]{2}}/view/:int/:params", array(
  114. 'controller' => 'products',
  115. 'action' => 'view',
  116. 'id' => 2,
  117. 'lang' => 1,
  118. ));
  119.  
  120. $router->add('/{language:[a-z]{2}}/news/:int/:params', array(
  121. 'controller' => "news",
  122. 'action' => "view",
  123. 'lang' => 1,
  124. 'id' => 2,
  125. 'slug' => 3,
  126. ));
  127.  
  128. $router->add("/{language:[a-z]{2}}", array(
  129. 'lang' => 1,
  130. ));
  131.  
  132. return $router;
  133.  
  134. });
  135.  
  136. $this->setDI($di);
  137. }
  138.  
  139. public function main()
  140. {
  141. $this->_registerServices();
  142.  
  143. //Register the installed modules
  144. $this->registerModules(array(
  145. 'frontend' => array(
  146. 'className' => 'Multiple\Frontend\Module',
  147. 'path' => '../apps/frontend/Module.php'
  148. )
  149. ));
  150.  
  151. $request = new Phalcon\Http\Request();
  152. echo $this->handle($request->getURI())->getContent();
  153. }
  154.  
  155. }
  156.  
  157. $application = new Application();
  158. $application->main();